package com.itheima.score.controller;

import com.itheima.score.entity.ResponseResult;
import com.itheima.score.pojo.User;
import com.itheima.score.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Name LoginController
 * @Author BaiXin
 * @Date 2022-10-25 16:46
 */
@RestController
@RequestMapping("/v1/login")
@Slf4j
public class LoginController {
    @Autowired
    UserService userService;

    @GetMapping("/{mobile}")
    public ResponseResult findByMobile(@PathVariable("mobile") String mobile) {
        log.warn("{}",mobile);
        ResponseResult result = userService.findByMobile(mobile);
        return result;
    }

    @PostMapping("/in")
    public ResponseResult in(@RequestBody User user , HttpServletRequest request){
        ResponseResult result =   userService.login(user);
        request.getSession().setAttribute("classId", user.getClassId());
        return result;
    }
}
